package com.oa.modules.approvalsec1.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.oa.modules.approvalsec1.entity.RoomStoreEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;
/**
 * 存放房间表
 *
 * @author jiangwei
 * @email 785297226@qq.com
 * @date 2021-04-06 14:12:59
 */
@Mapper
public interface RoomStoreDao extends BaseMapper<RoomStoreEntity> {


    /**
     * 查询总条数
     *
     * @author jiangwei
     * @email 785297226@qq.com
     * @date 2021-04-06 14:12:59
     * @Description 查询分页数据
     */
    @Select("<script>SELECT COUNT( 1 ) FROM (" +
            "select t1.* from room_store t1  " +
            "where 1=1 " +
            "<if test = 'params != null '> "+
            "and t1.`STATUS` = #{params.status} " +
            ") </if> TOTAL</script>")
    long findPage(@Param("params") Map<String, Object> params);

    /**
     * 查询分页数据
     *
     * @author jiangwei
     * @email 785297226@qq.com
     * @date 2021-04-06 14:12:59
     * @Description 查询分页数据
     */
    @Select("<script>select t1.* from room_store t1 " +
            "where 1=1 " +
            "and t1.`STATUS` = #{params.status} " +
            "ORDER BY t1.CREATE_DATE desc</script>")
    List<RoomStoreEntity> findRecords(IPage<RoomStoreEntity> page, @Param("params") Map<String, Object> params);


    /**
     * 查询一个小时以前的数据
     */
    @Select("<script>SELECT ID " +
            "FROM room_store " +
            "WHERE CREATE_DATE >DATE_ADD(NOW(),INTERVAL - 15 MINUTE)</script>")
    List<String> queryByAllRoom();

    /**
     * 查询一个小时以前的数据
     */
    @Select("<script>SELECT * " +
            "FROM room_store " +
            "WHERE room_num = #{roomNum} </script>")
    RoomStoreEntity queryByRoom(@Param("roomNum") String roomNum);
}
